package a10_动态规划;

/**
 * <p>
 * a46_最大子序和复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/3/4
 */
public class a46_最大子序和复习2 {
    public int maxSubArray(int[] nums) {
        int result = nums[0];

        int[] dp = new int[nums.length];
        dp[0] = nums[0];

        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(nums[i],dp[i-1]+nums[i]);
            result = Math.max(result, dp[i]);
        }

        return result;
    }
}
